#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e3+5;
int n, l, r, ans;
struct node{
	string type, str;
}s[MAXN];
bool check(string s){
	int tmp = 0;
	for (int i = 0; i < s.length(); i ++){
		if (s[i] == '.'){
			if (tmp > 255 || tmp < 0) return 1;
			tmp = 0;
		} else if (s[i] != ':'){
			tmp = tmp*10 + s[i] - '0';
		} else if (s[i] == ':') tmp = 0;
	}
	if (tmp < 0 || tmp > 65535) return 1;
	return 0;
}
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	cin >> n;
	for (int i = 1; i <= n; i ++){
		cin >> s[i].type >> s[i].str;
		if (check(s[i].str)){
			cout << "ERR" << endl;
			continue;
		}
		bool flag = 1;
		if (s[i].type == "Server"){
			for (int j = 1; j < i; j ++){
				if (s[j].type == "Server"  && s[i].str == s[j].str){
					cout << "FAIL" << endl;
					flag = 0;
					break;
				}
			}
			if (flag) cout << "OK" << endl;
		} else if (s[i].type == "Client"){
			for (int j = 1; j < i; j ++){
				if (s[j].type == "Server" && s[i].str == s[j].str){
					cout << j << endl;
					flag = 0;
					break;
				}
			}
			if (flag) cout << "FAIL" << endl;
		}
	}
	return 0;
} 
